<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>列表</title>
</head>
<body>
	<div class="layui-collapse">
		<div class="layui-colla-item">
			<h2 class="layui-colla-title">绩效信息</h2>
			<div class="layui-colla-content layui-show">
				<fieldset class="layui-elem-field layui-field-title">
					<legend>查询条件</legend>
					<div class="layui-field-box">
						<form class="layui-form">
							<div class="layui-form-item">
								<label class="layui-form-label">员工编号</label>
								<div class="layui-input-inline">
									<input type="text" name="codeEmp" placeholder="请输入员工编号"
										autocomplete="off" class="layui-input">
								</div>
								<label class="layui-form-label">项目编号</label>
								<div class="layui-input-inline">
									<input type="text" name="codePro" placeholder="请输入项目编号"
										autocomplete="off" class="layui-input">
								</div>
								<label class="layui-form-label"></label>
								<div class="layui-input-inline">
									<input type="button" class="layui-btn" lay-submit
										lay-filter='sel' value='查询'> <input type="reset"
										class="layui-btn layui-btn-primary" value='重置'>
								</div>
								<input type="button" class="layui-btn " value='添加' onclick='openAdd()'>
							</div>
							<input type="hidden" name='action' value='list' /> 
							<input type="hidden" name='pageIndex' value='1' /> 
							<input type="hidden" name='pageLimit' value='10' />
						</form>
					</div>
				</fieldset>
			</div>
		</div>
	</div>
	<table class='layui-table'>
		<colgroup>
			<col width="10%">
			<col width="10%">
			<col width="10%">
			<col width="15%">
			<col width="15%">
			<col width="15%">
			<col width="15%">
			<col>
		</colgroup>
		<thead>
			<tr>
				<th>序号</th>
				<th>编号</th>
				<th>员工编号</th>
				<th>项目编号</th>
				<th>评分</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id='user_tbody'></tbody>
	</table>
	<div id="pageInfo" style="text-align: right; padding-right: 30px"></div>
	<!-- 	分页标签 -->

	<script type="text/javascript">
		element.render();//渲染
		
		fromOn('/score', 'submit(sel)', 'json', function(data) {
			console.log(data)
			var pageIndex = $("input[name='pageIndex']").val();
			var pageLimit = $("input[name='pageLimit']").val();
			setPageInfo('pageInfo', data.count, pageIndex, pageLimit, function(
					obj, first) {
				$("input[name='pageIndex']").val(obj.curr);//得到当前页，以便向服务端请求对应页的数据
				$("input[name='pageLimit']").val(obj.limit);//得到每页显示天数
				if (!first) {//首次不执行
					refresh()
				}
			})
			var html = ''
			$.each(data.data, function(index, element) {//模板引擎
				element.idA = (index + 1)+(pageIndex-1)*pageLimit
				html += laytpl($("#tradd").html()).render(element)
			})
			$("#user_tbody").html(html);
		})


		refresh();
		function refresh() {//打开时自动点击查询显示数据
			$("input[value='查询']").click();
		}
		function openAdd() {
			openLayer("/web/page/score/add.jsp", refresh)
		}
		function del(id) {
			layer.confirm("确定是否删除？", {
				icon : 3,
				title : '提示'
			}, function(index) {
				ajax('/score', {
					id : id,
					action : 'del'
				}, 'text', function(data) {
					if (1 == data) {
						layer.msg("删除成功", refresh)
					} else {
						layer.msg("删除失败")
					}
				})
			});
		}
		function openUpd(id) {
			openLayer("/web/page/score/upd.jsp?id=" + id, refresh)
		}

	</script>
	<script type="text/html" id='tradd'>
<tr>
    <td>{{d.idA}}</td>
	<td>{{d.id}}</td>
	<td>{{d.codeEmp}}</td>
	<td>{{d.codePro}}</td>
	<td>{{d.score}}</td>
    <td>
        <a href="javascript:del('{{d.id}}');" class='layui-btn layui-btn-sm layui-btn-danger'>
			<i class='layui-icon layui-icon-delete'></i>
		</a>
        <input onclick='openUpd("{{d.id}}")' type='button' value='修改' class='layui-btn layui-btn-sm'/>
    </td>
</tr>
</script>
</body>
</html>